home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / doc / library.n < prev    next >
Text File  |  1993-02-14  |  9KB  |  224 lines

  1. '\"
  2. '\" Copyright 1991-1992 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. .so man.macros
  11. .HS library tcl
  12. .BS
  13. .SH NAME
  14. library \- standard library of Tcl procedures
  15. .SH SYNOPSIS
  16. .nf
  17. \fBauto_execok \fIcmd\fR
  18. \fBauto_load \fIcmd\fR
  19. \fBauto_mkindex \fIdir pattern\fR
  20. \fBauto_reset\fR
  21. \fBparray \fIarrayName\fR
  22. \fBunknown \fIcmd \fR?\fIarg arg ...\fR?
  23. .fi
  24. .BE
  25.  
  26. .SH INTRODUCTION
  27. .PP
  28. Tcl includes a library of Tcl procedures for commonly-needed functions.
  29. The procedures defined in the Tcl library are generic ones suitable
  30. for use by many different applications.
  31. The location of the Tcl library is returned by the \fBinfo library\fR
  32. command.
  33. In addition to the Tcl library, each application will normally have
  34. its own library of support procedures as well;  the location of this
  35. .VS
  36. library is normally given by the value of the \fB$\fIapp\fB_library\fR
  37. global variable, where \fIapp\fR is the name of the application.
  38. For example, the location of the Tk library is kept in the variable
  39. \fB$tk_library\fR.
  40. .VE
  41. .PP
  42. To access the procedures in the Tcl library, an application should
  43. source the file \fBinit.tcl\fR in the library, for example with
  44. the Tcl command
  45. .DS
  46. \fBsource [info library]/init.tcl
  47. .DE
  48. This will define the \fBunknown\fR procedure and arrange for the
  49. other procedures to be loaded on-demand using the auto-load
  50. mechanism defined below.
  51.  
  52. .SH "COMMAND PROCEDURES"
  53. .PP
  54. The following procedures are provided in the Tcl library:
  55. .TP
  56. \fBauto_execok \fIcmd\fR
  57. Determines whether there is an executable file by the name \fIcmd\fR.
  58. This command examines the directories in the current search path
  59. (given by the PATH enviornment variable) to see if there is an
  60. executable file named \fIcmd\fR in any of those directories.
  61. If so, it returns 1;  if not it returns 0.  \fBAuto_exec\fR
  62. remembers information about previous searches in an array
  63. named \fBauto_execs\fR;  this avoids the path search in
  64. future calls for the same \fIcmd\fR.  The command \fBauto_reset\fR
  65. may be used to force \fBauto_execok\fR to forget its cached
  66. information.
  67. .TP
  68. \fBauto_load \fIcmd\fR
  69. This command attempts to load the definition for a Tcl procedure named
  70. \fIcmd\fR.
  71. To do this, it searches an \fIauto-load path\fR, which is a list of
  72. one or more directories.
  73. The auto-load path is given by the global variable \fB$auto_path\fR
  74. if it exists.
  75. If there is no \fB$auto_path\fR variable, then the TCLLIBPATH environment
  76. variable is used, if it exists.
  77. Otherwise the auto-load path consists of just the Tcl library directory.
  78. Within each directory in the auto-load path there must be a file
  79. \fBtclIndex\fR that describes the procedures defined in that directory
  80. and the file in which each procedure is defined.  The \fBtclIndex\fR
  81. file should be generated with the \fBauto_mkindex\fR command.
  82. If \fIcmd\fR is found in an index file, then the appropriate
  83. script is \fBsource\fRd to create the procedure.
  84. The \fBauto_load\fR command returns 1 if the script was successfully
  85. sourced and \fIcmd\fR now exists.
  86. The command returns 0 if there was no index entry for \fIcmd\fR
  87. or if the script didn't actually define \fIcmd\fR (e.g. because
  88. index information is out of date).
  89. If an error occurs while processing the script, then that error
  90. is returned.
  91. \fBAuto_load\fR only reads the index information once and saves it
  92. in the array \fBauto_index\fR;  future calls to \fBauto_load\fR
  93. check for \fIcmd\fR in the array rather than re-reading the index
  94. files.
  95. The cached index information may be deleted with the command
  96. \fBauto_reset\fR.
  97. This will force the next \fBauto_load\fR command to reload the
  98. index database from disk.
  99. .TP
  100. \fBauto_mkindex \fIdir pattern\fR
  101. Generates an index suitable for use by \fBauto_load\fR.
  102. The command searches \fIdir\fR for all files whose names match
  103. \fIpattern\fR (matching is done with the \fBglob\fR command),
  104. generates an index of all the Tcl command
  105. procedures defined in all the matching files, and stores the
  106. index information in a file named \fBtclIndex\fR in \fIdir\fR.
  107. For example, the command
  108. .RS
  109. .DS
  110. \fBauto_mkindex foo *.tcl\fR
  111. .DE
  112. .LP
  113. will read all the \fB.tcl\fR files in subdirectory \fBfoo\fR
  114. and generate a new index file \fBfoo/tclIndex\fR.
  115. .PP
  116. \fBAuto_mkindex\fR parses the Tcl scripts in a relatively
  117. unsophisticated way:  if any line contains the word \fBproc\fR
  118. as its first characters then it is assumed to be a procedure
  119. definition and the next word of the line is taken as the
  120. procedure's name.
  121. Procedure definitions that don't appear in this way (e.g. they
  122. have spaces before the \fBproc\fR) will not be indexed.
  123. .RE
  124. .TP
  125. \fBauto_reset\fR
  126. Destroys all the information cached by \fBauto_execok\fR and
  127. \fBauto_load\fR.
  128. This information will be re-read from disk the next time it is
  129. needed.
  130. .VS
  131. \fBAuto_reset\fR also deletes any procedures listed in the auto-load
  132. index, so that fresh copies of them will be loaded the next time
  133. that they're used.
  134. .VE
  135. .TP
  136. \fBparray \fIarrayName\fR
  137. Prints on standard output the names and values of all the elements
  138. in the array \fIarrayName\fR.
  139. .VS
  140. \fBArrayName\fR must be an array accessible to the caller of \fBparray\fR.
  141. It may be either local or global.
  142. .VE
  143. .TP
  144. \fBunknown \fIcmd \fR?\fIarg arg ...\fR?
  145. This procedure is invoked automatically by the Tcl interpreter
  146. whenever the name of a command doesn't exist.
  147. The \fBunknown\fR procedure receives as its arguments the
  148. name and arguments of the missing command.
  149. \fBUnknown\fR first calls \fBauto_load\fR to load a procedure for
  150. the command.
  151. If this succeeds, then it executes the original command with its
  152. original arguments.
  153. If the auto-load fails then \fBunknown\fR calls \fBauto_execok\fR
  154. to see if there is an executable file by the name \fIcmd\fR.
  155. If so, it invokes the Tcl \fBexec\fR command
  156. with \fIcmd\fR and all the \fIargs\fR as arguments.
  157. If \fIcmd\fR can't be auto-executed, \fBunknown\fR checks to
  158. see if the command was invoked at top-level and outside of any
  159. script.  If so, then \fBunknown\fR takes takes two additional steps.
  160. First, it sees if \fIcmd\fR has one of the following three forms:
  161. \fB!!\fR, \fB!\fIevent\fR, or \fB^\fIold\fB^\fInew\fR?\fB^\fR?.
  162. If so, then \fBunknown\fR carries out history substitution
  163. in the same way that \fBcsh\fR would for these constructs.
  164. Second, and last, \fBunknown\fR checks to see if \fIcmd\fR is
  165. a unique abbreviation for an existing Tcl command.
  166. If so, it expands the command name and executes the command with
  167. the original arguments.
  168. If none of the above efforts has been able to execute
  169. the command, \fBunknown\fR generates an error return.
  170. If the global variable \fBauto_noload\fR is defined, then the auto-load
  171. step is skipped.
  172. If the global variable \fBauto_noexec\fR is defined then the
  173. auto-exec step is skipped.
  174. Under normal circumstances the return value from \fBunknown\fR
  175. is the return value from the command that was eventually
  176. executed.
  177.  
  178. .SH "VARIABLES"
  179. .PP
  180. The following global variables are defined or used by the procedures in
  181. the Tcl library:
  182. .TP
  183. \fBauto_execs\fR
  184. Used by \fBauto_execok\fR to record information about whether
  185. particular commands exist as executable files.
  186. .TP
  187. \fBauto_index\fR
  188. Used by \fBauto_load\fR to save the index information read from
  189. disk.
  190. .TP
  191. \fBauto_noexec\fR
  192. If set to any value, then \fBunknown\fR will not attempt to auto-exec
  193. any commands.
  194. .TP
  195. \fBauto_noload\fR
  196. If set to any value, then \fBunknown\fR will not attempt to auto-load
  197. any commands.
  198. .TP
  199. \fBauto_path\fR
  200. If set, then it must contain a valid Tcl list giving directories to
  201. search during auto-load operations.
  202. .TP
  203. \fBenv(TCL_LIBRARY)\fR
  204. .VS
  205. If set, then it specifies the location of the directory containing
  206. library scripts (the value of this variable will be returned by
  207. the command \fBinfo library\fR).  If this variable isn't set then
  208. a default value is used.
  209. .VE
  210. .TP
  211. \fBenv(TCLLIBPATH)\fR
  212. If set, then it must contain a valid Tcl list giving directories to
  213. search during auto-load operations.
  214. This variable is only used if \fBauto_path\fR is not defined.
  215. .TP
  216. \fBunknown_active\fR
  217. This variable is set by \fBunknown\fR to indicate that it is active.
  218. It is used to detect errors where \fBunknown\fR recurses on itself
  219. infinitely.
  220. The variable is unset before \fBunknown\fR returns.
  221.  
  222. .SH KEYWORDS
  223. auto-exec, auto-load, library, unknown
  224.